<?php

/**
 * Class: usermanagement
 * @author ovo
 * This class allows the admin to manage all the user activities
 *
 */
class Admin_usermanagementController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        // action body
     
        $this->view->title = "All users within the Application";
        $users = new Admin_Model_DbTable_Users();
        $this->view->users = $users->getAllUsers();
    }

    public function listusersAction()
    {
        // action body
        $this->view->title = "All users within the Application";
        $users = new Admin_Model_DbTable_Users();
        $list = $users->getAllUsers();
        
        $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($list));
        $paginator->setItemCountPerPage(5)
        		  ->setCurrentPageNumber($this->_getParam('page', 1));
        
        $this->view->paginator = $paginator;
    }

    public function registerAction(){
    	
    	$this->view->form = new Admin_Form_Registration();
    }
    
    /**
     * Function: deluser
     * This function removes a user completely from the database
     */
    public function deluserAction(){
    	
    	$id = $this->_getParam('id');
    	$users = new Admin_Model_DbTable_Users();
    	$users->deleteUser($id);
    	//$this->_redirect('/');
    	$this->_forward('listusers','usermanagement', 'admin');
    }
    

    
    public function avgratingsAction(){
    	
    	$rats = new Model_DbTable_rate();
    	$vals = $rats->avgRatings();
    	$this->pagination($vals, 1);
    }
    
    public function viewcommentsAction(){
    	
    	$this->view->title= "User Comments";
    	$rats = new Model_DbTable_rate();
    	$comments = $rats->viewComments();
    	$this->pagination($comments, 7);
    }
    

	private function pagination($resultset, $count){
        $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($resultset));
        $paginator->setItemCountPerPage($count)	        
        		  ->setCurrentPageNumber($this->_getParam('page', 1));
        $this->view->paginator = $paginator;
		}
}



